package xixirupan.tmgp.tencent.com.vmeim.ui.beautycircle.model;

import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import xixirupan.tmgp.tencent.com.vmeim.config.URLConfig;
import xixirupan.tmgp.tencent.com.vmeim.retrofit.IEssnseR;

/**
 * Created by lenovo on 2016/10/20.
 */

public class EssenseBiz {


    IBeautyCircle iBeautyCircle;
      private static final String PAGE_SIZE = "pageSize";
    private static final String PAGE_NO = "pageNo";
    private   int  pageSize= 20;
    private   int  pageNo = 1;
     private List<Object> lists;


    public  void getData(final IBeautyCircle iBeautyCircle, int pageSize, int pageNo)
    {
        this.pageNo =pageNo;
        this.pageSize =pageSize;
        this.iBeautyCircle =iBeautyCircle;
        lists =new ArrayList<>();
        Retrofit retrofit =new Retrofit.Builder().baseUrl(URLConfig.Url.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        HashMap<String,String> hashMap =new HashMap<>();
        hashMap.put(PAGE_SIZE,pageSize+"");
        hashMap.put(PAGE_NO,pageNo+"");
        IEssnseR iEssnseR = retrofit.create(IEssnseR.class);
        Call<EssenseBean> call = iEssnseR.esseseData(hashMap);
        call.enqueue(new Callback<EssenseBean>() {
            @Override
            public void onResponse(Call<EssenseBean> call, Response<EssenseBean> response) {
                EssenseBean body = response.body();
                DataBaen data = body.getData();
                List<PostsBaen> posts = data.getPosts();
                List<Map<String,String>> lists_item1 =new ArrayList<Map<String, String>>();
                for (int i = 0; i < posts.size(); i++) {
                    //类型标题
                    String typeTitle = posts.get(i).getTypeTitle();
                    String _headUrl = posts.get(i).getHeadPicUrl();
                    String headUrl = URLConfig.Url.ESSENSE_ICON+_headUrl;
                    String nickname = posts.get(i).getNickname();
                    String userGradeName = posts.get(i).getUserGradeName();
                    Map<String,String> map =new HashMap<String, String>();
                    map.put("headUrl",headUrl);
                    map.put("nickname",nickname);
                    map.put("typeTitle",typeTitle);
                    map.put("userGradeName",userGradeName);
                    lists_item1.add(map);
                    lists.add(lists_item1);  //第一种布局的数据源

                    lists.add(posts.get(i));//第二种数据源 PostsBaen

                }
                Log.i("TAG","_-下载成功---------->数据源个数"+lists.size());
                iBeautyCircle.postEssenseData(lists);
            }

            @Override
            public void onFailure(Call<EssenseBean> call, Throwable t) {
                Log.i("精华部分数据请求失败","-------------->"+t.getMessage());
            }
        });

    }
}
